package com.example.yuntiku.Service;

import com.example.yuntiku.Vo.ExamVo;
import com.example.yuntiku.Vo.PagerVo;
import com.example.yuntiku.dao.TestrecordDao;
import com.example.yuntiku.dao.UserDao;
import com.example.yuntiku.dao.impl.ExamDaoImpl;
import com.example.yuntiku.dao.impl.PagerDaoImpl;
import com.example.yuntiku.dao.impl.TestrecordDaoImpl;
import com.example.yuntiku.dao.impl.UserDaoImpl;
import com.example.yuntiku.entity.Exam;
import com.example.yuntiku.entity.Pager;
import com.example.yuntiku.entity.Testrecord;
import com.example.yuntiku.entity.User;

import java.util.List;

public class ExamService {
    ExamDaoImpl examDao=new ExamDaoImpl();
    UserDao userDao = new UserDaoImpl();
    TestrecordDao testrecordDao = new TestrecordDaoImpl();
    /**
     * 添加自测
     * @return
     */
    public int insertExam(Exam exam){
        //第一步添加测试
        return examDao.insertExam(exam);
        //添加学生测试记录
    }

    /**
     * 添加统一测试
     * @param exam
     * @param classIds
     * @return
     */
    public int insertExam1(Exam exam,String[] classIds){
        //第一步添加测试
        int examId = examDao.insertExam(exam);

        //添加学生测试记录
        List<User> users = userDao.selectByClassId(classIds);
        for (User user : users) {
            Testrecord testrecord = new Testrecord();
            testrecord.setExamid(examId);
            testrecord.setSid(user.getUid());
            testrecordDao.insertTestrecord(testrecord);
        }
        return 1;
    }
    public List<ExamVo> selectPager(String pagername, String starttime, int page, int size){
        //调用dao的数据直接返回
        return examDao.selectPager(pagername,starttime,page,size);
    }
    public int selectcount(String name, String date){
        return examDao.selectcount(name,date);
    }
    public List<Exam> selectAll(){
        //调用dao的数据直接返回
        return examDao.selectAll();
    }

}
